/**
 * @description 管理聊天相关的信息 包括当前聊天信息
 * @author wyvonj
 * @date 2019-08-01
 */

import { Commit } from 'vuex';

const state: any = {
  // 存储所有群信息;
  storeGroupList: [],
  // 存储群聊页面的群信息;
  groupInfoList: {},
  currentGroup: {},
  groupSetting: {
    info: {

    }
  }, // 群设置信息
  isShutup: 0, // 是否4443
  recentSessMap: {}, // 保存最近会话列表
  getPrePageC2CHistroyMsgInfoMap: {}, // 保存最近会话列表
  getPrePageGroupHistroyMsgInfoMap: {}, // 保存最近会话列表
  wxShareData: {},
};

const mutations: any = {
  saveGroupList(states: any, params: Array<any>) {
    states.storeGroupList = params;
  },
  saveWxShareData(states: any, params: object) {
    states.wxShareData = params;
  },
  saveCurrentGroup(states: any, params: object) {
    states.currentGroup = params;
  },
  saveGroupSetting(states: any, params: object) {
    states.groupSetting = params;
  },
  saveRecentSessMap(states: any, params: object) {
    let newState = Object.assign(state.recentSessMap, params);
    states.recentSessMap = newState;
  },
  saveGetPrePageC2CHistroyMsgInfoMap(states: any, params: object) {
    let newState = Object.assign(state.getPrePageC2CHistroyMsgInfoMap, params);
    states.getPrePageC2CHistroyMsgInfoMap = newState;
  },
  saveGetPrePageGroupHistroyMsgInfoMap(states: any, params: object) {
    let newState = Object.assign(state.getPrePageGroupHistroyMsgInfoMap, params);
    states.getPrePageGroupHistroyMsgInfoMap = newState;
  },

};

const actions: any = {
  saveWxShareDataFN(context: { commit: Commit }, params: object) {
    context.commit('saveWxShareData', params);
  },
  saveGroupListFN(context: { commit: Commit }, params: object) {
    context.commit('saveGroupList', params);
  },
  saveCurrentGroupFN(context: { commit: Commit }, params: object) {
    context.commit('saveCurrentGroup', params);
  },
  saveGroupSettingFN(context: { commit: Commit }, params: object) {
    context.commit('saveGroupSetting', params);
  },
  saveRecentSessMapFN(context: { commit: Commit }, params: object) {
    context.commit('saveRecentSessMap', params);
  },
  saveGetPrePageC2CHistroyMsgInfoMapFN(context: { commit: Commit }, params: object) {
    context.commit('saveGetPrePageC2CHistroyMsgInfoMap', params);
  },
  saveGetPrePageGroupHistroyMsgInfoMapFN(context: { commit: Commit }, params: object) {
    context.commit('saveGetPrePageGroupHistroyMsgInfoMap', params);
  },

};

export default {
  namespaced: true, // namespaced为false的时候，state,mutations,actions全局可以调用，为true，生成作用域，引用时要声明模块名称
  state,
  mutations,
  actions,
};